package edu.famework.weekly4W;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class ComparatorImpl implements Comparator<Student> {


    @Override
    public int compare(Student o1, Student o2) {
        if (o1.getSno() == o2.getSno()){
            return  -1;
        }else if(o1.getSno() == o2.getSno()){
            return 0;
        }else{
            return 1;
        }
    }
    public static void main(String[] args) {
        List<Student> list = new ArrayList<>();
        Student s1 = new Student(1002,"赵四");
        Student s2 = new Student(1004,"张三");
        Student s3 = new Student(1001,"刘能");
        Student s4 = new Student(1003,"王五");
        list.add(s1);
        list.add(s2);
        list.add(s3);
        list.add(s4);

        for (Student s:list) {
            System.out.println(s.getSno()+"----"+s.getName());
        }

        //根据编号排序
        Collections.sort(list,new ComparatorImpl());
        System.out.println("----------------------------------");

        for (Student s:list) {
            System.out.println(s.getSno()+"----"+s.getName());
        }

    }
}
